package com.baidu.infinity.ui.fragment.home.shape.shapes

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode
import android.os.Build
import androidx.annotation.RequiresApi
import com.baidu.infinity.ui.fragment.home.shape.BaseShape
import com.baidu.infinity.ui.util.state.ShapeState

class EraserShape: BaseShape() {
    override fun setStartPoint(startX: Float, startY: Float) {
        super.setStartPoint(startX, startY)
        mPaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_OUT)
        mPaint.strokeWidth = 5f
        mPath.moveTo(startX,startY)

    }
    override fun setEndPoint(endX: Float, endY: Float) {
        super.setEndPoint(endX, endY)
        mPath.lineTo(endX,endY)
    }
    @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
    override fun draw(canvas: Canvas) {
        super.draw(canvas)
        mPaint.style = Paint.Style.STROKE
        canvas.drawPath(mPath,mPaint)
        if(mState == ShapeState.DRAWING){
            mPaint.color = Color.WHITE
            mPaint.style = Paint.Style.FILL
            canvas.drawCircle(endX,endY,10f,mPaint)
        }
    }

    override fun containsPoint(x: Float, y: Float): Boolean {
        return false
    }
}